/**
 * 选择排序
 */

#include <iostream>
#include <vector>

using namespace std;

void selectionSort(vector<int> &v)
{
    int n = v.size();
    for (int i = 0; i < n - 1; ++i)
    {
        int min = i;
        for (int j = i + 1; j < n; ++j)
        {
            if (v[min] > v[j])
            {
                min = j;
            }
        }
        int nTemp = v[min];
        v[min] = v[i];
        v[i] = nTemp;
    }
}

void printResult(vector<int> &v)  
{
    for (const auto &n : v) {
        cout << n << " ";
    }
    cout << endl;
}

int main()
{
    vector<int> vTest = {1, 3, 45, 7, 2, 7, 3, 76};
    printResult(vTest);
    selectionSort(vTest);
    printResult(vTest);
    return 0;
}